{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Interactive Recomputation\n",
    "\n",
    "The widgets work with the [interact API](http://ipywidgets.readthedocs.io/en/latest/examples/Using%20Interact.html), so that a cell can be recomputed as the widgets change value.  This API is slated for improvement see [#5867](https://github.com/twosigma/beakerx/issues/5867)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import static com.twosigma.beakerx.groovy.widgets.Interactive.interact\n",
    "\n",
    "class DataHolder{\n",
    "    static Plot plot = null;\n",
    "}\n",
    "\n",
    "public static Object f(a,b){\n",
    "    if (DataHolder.plot == null){\n",
    "        DataHolder.plot = new Plot(title: \"Lissajous Curves\")\n",
    "    }\n",
    "\n",
    "    List t = (1..1000)\n",
    "    List x = t.collect { it -> sin(it*a/100)}\n",
    "    List y = t.collect { it -> cos(it*b/100)}\n",
    "    \n",
    "    DataHolder.plot.getGraphics().clear()\n",
    "    DataHolder.plot.add(new Line(x: x, y: y))\n",
    "    return DataHolder.plot \n",
    "}\n",
    "\n",
    "interact(this.&f, 3d, -3d);"
   ]
  }
 ],
 "metadata": {
  "beakerx_kernel_parameters": {},
  "kernelspec": {
   "display_name": "Groovy",
   "language": "groovy",
   "name": "groovy"
  },
  "language_info": {
   "codemirror_mode": "groovy",
   "file_extension": ".groovy",
   "mimetype": "",
   "name": "Groovy",
   "nbconverter_exporter": "",
   "version": "2.4.3"
  },
  "widgets": {
   "state": {
    "8e031bec-8956-4228-9da0-77339eee6003": {
     "views": [
      {
       "cell_index": 0
      }
     ]
    }
   },
   "version": "1.2.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
